package com.faithnmn.radio;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.faithnmn.radio.common.Constants;
import com.faithnmn.radio.service.RadioOnlineService;

public class MainActivity extends Activity implements OnClickListener{
public static TextView playPause;
public static TextView status;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		playPause = (TextView) findViewById(R.id.playstopBtn);
		status = (TextView) findViewById(R.id.status);
		if(RadioOnlineService.isPlaying){
			playPause.setText("Pause Radio");
		}else{
			playPause.setText("Play Radio");
		}
		playPause.setOnClickListener(this);
		Intent startRadio = new Intent(this,RadioOnlineService.class);
		startService(startRadio);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.playstopBtn:
			Intent startRadio = new Intent(this, RadioOnlineService.class);
			if(RadioOnlineService.isPlaying){
				playPause.setText("Play Radio");
				startRadio.setAction(Constants.STOP_RADIO_ACTION);
			}else{
				playPause.setText("Pause Radio");
				startRadio.setAction(Constants.START_RADIO_ACTION);
				status.setText("Please wait..");
			}
			startService(startRadio);
			break;

		default:
			break;
		}
	}

}
